export default {
	state: {
		originalDate: [],
		categoryData: [],
		currentId: 0,
		currentIndex: 0,
	},
	getters: {
		leftData: (state) => {
			let arr = []
			arr = state.originalDate.filter(v => {
				return v.level == 1
			})
			return arr
		},
		rightData: (state) => {
			let arr = []
			if(state.originalDate[state.currentIndex] && state.originalDate[state.currentIndex].child) {
				arr = state.originalDate[state.currentIndex].child;
			}
			
			let a1 = []
			let a2 = []
			arr.forEach(ele => {
				if (ele.child) {
					a1.push(ele)
				} else {
					a2.push(ele)
				}
			});

			return [a1, a2];
		},
		currentNavList: (state) => {
			let arr = []
			if (state.currentId < 1) return;
			let item = state.originalDate.filter(v => {return v.id == state.currentId})[0]
			if (item.level == 1) {
				arr = state.originalDate.filter(v => {
					return v.level == 1
				})
			} else {
				arr = state.originalDate.filter(v => {
					return v.parentId == item.parentId
				})
			}
			return arr
		}
	},
	mutations: {
		// 初始化接口返回来的原始数组
		initOriginalDate(state, data) {
			let originalDate = uni.getStorageSync('originalDate')
			if (originalDate) {
				originalDate = JSON.parse(originalDate)
				state.originalDate = originalDate;
			}
		},
		changeIndex(state, index) {
			index ? index : 0;
			state.currentIndex = index;
		},
		changeCurrentId(state, id) {
			id ? id : 0;
			state.currentId = id;
		}

	}
}
